package com.game.chessgame;

public class Pawn extends Piece {
    public Pawn(Player player) {
        super(player);
    }

    @Override
    public char getSymbol() {
        return (player == Player.WHITE) ? 'P' : 'p';
    }

    @Override
    public boolean canMove(int fromX, int fromY, int toX, int toY, Piece[][] board) {
        int direction = (player == Player.WHITE) ? -1 : 1;
        if (fromX == toX) {
            if (toY == fromY + direction) {
                return board[toY][toX] == null;
            }
            if (fromY == ((player == Player.WHITE) ? 6 : 1) && toY == fromY + 2 * direction) {
                return board[toY][toX] == null && board[fromY + direction][toX] == null;
            }
        }
        if (Math.abs(fromX - toX) == 1 && toY == fromY + direction) {
            return board[toY][toX] != null && board[toY][toX].getPlayer() != player;
        }
        return false;
    }
}